<template>
  <div class="publish">
    <Secondarytitle :titlename="'发布统计'" />

    <div class="my-row">
      <van-row>
        <van-col span="8">已发布: 0</van-col>
        <van-col span="8" @click="onNewpage">未完成: 0</van-col>
        <van-col span="8">已完成: 0</van-col>
      </van-row>
    </div>
    <Secondarytitle :titlename="'我要发布'" />

    <div>
      <optionbtn :option-name="'发布任务'" @onclick="onNewpage" />
      <optionbtn :option-name="'修改任务'" @onclick="onUpdataTask" />
      <optionbtn :option-name="'删除任务'" />
    </div>
    <Secondarytitle :titlename="'任务列表'" />
    <itemVue v-for="item in taskarr" :titlename="item.title" :price="item.price" :label="item.select" :orderBtn="'订单完成'"
      :_id="item._id" @success="onsuccess" />
  </div>
</template>
  
<script>
import Secondarytitle from '@/components/secondarytitle.vue'
import itemVue from '@/components/item.vue'
import optionbtn from '@/components/optionsbutton.vue'
import { Myorder, successtask } from '@/axios/index.js'
import { mapState } from 'vuex';
export default {
  components: {
    Secondarytitle,
    itemVue,
    optionbtn
  },
  data() {
    return {
      taskarr: []
    }
  },
  computed: {
    ...mapState([
      'user'
    ])
  },
  methods: {
    onNewpage(a) {
      // console.log(a);
      this.$router.push('/home/publish/newTask')
    },
    onUpdataTask() {
      this.$router.push('/home/publish/updataTask')
    },
    onsuccess(e) {//完成
      successtask({ upkey: { _id: e }, upval: { status: 2 } })
        .then((res) => {
          console.log(res);
          this.taskarr = this.taskarr.filter((item)=>item._id!==e)
        })
    }
  },
  created() {
    Myorder({ userId: this.user.userId,status:1 })
      .then((res) => {
        console.log(res.data.newTask);
        this.taskarr = res.data.newTask
      })
  }
}
</script>
  
<style lang="less" scoped>
.publish {
  padding: 10px;
  background: rgb(243, 241, 222);

  .my-row {
    overflow: hidden;
    text-align: center;
    position: relative;
    background: rgb(255, 255, 255);
    padding: 10px 15px;
    border-radius: 5px;

    .van-col {
      height: 50px;
      line-height: 50px;
    }

    .van-row::before {
      content: '';
      background: rgb(195, 195, 195);
      height: 50px;
      position: absolute;
      width: 2px;
      left: 31vw;
    }

    .van-row::after {
      content: '';
      background: rgb(195, 195, 195);
      height: 50px;
      position: absolute;
      width: 2px;
      left: 63vw;
    }
  }


}
</style>

